﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Model;
using WCF_Client.ShowReference;
using WCF_Client.MovieReference;
using WCF_Client.CinemaHallReference;

namespace BioBooking
{
    public partial class ManageShows : Form
    {
        //private ShowController shows;
        //private MovieController movies;
        //private CinemaHallController halls;
        
        private ShowServiceClient showService;
        private MovieServiceClient movieService;
        private CinemaHallServiceClient cinemaService;

        
        public ManageShows()
        {
            InitializeComponent();
            //shows = new ShowController();
            //movies = new MovieController();
            //halls = new CinemaHallController();

            movieService = new MovieServiceClient();
            showService = new ShowServiceClient();
            cinemaService = new CinemaHallServiceClient();
            populateLists();
        }

        private void populateLists()
        {
            listBox1.Items.Clear();
            listBox2.Items.Clear();
            listBox3.Items.Clear();
            foreach (Movie m in movieService.FindAllMovies())
            {
                listBox1.Items.Add(m);
            }
            foreach (CinemaHall h in cinemaService.FindAllCinemaHalls())
            {
                listBox2.Items.Add(h);
            }
            foreach (Show s in showService.FindAllShows(true))
            {
                listBox3.Items.Add(s);
            }
        }
        private void button1_Click(object sender, EventArgs e)
        {
            Movie mov = new Movie();
            CinemaHall ch = new CinemaHall();
            mov = (Movie)listBox1.SelectedItem;
            ch = (CinemaHall)listBox2.SelectedItem;
            showService.CreateShow(mov.SerialNo, ch.Name, textBox1.Text, textBox2.Text, textBox3.Text);
            populateLists();
        }

        private void ManageShows_Load(object sender, EventArgs e)
        {

        }

        private void button2_Click(object sender, EventArgs e)
        {
            Show tempShow = (Show)listBox3.SelectedItem;
            try
            {
                showService.DeleteShow(tempShow.DateTimeStart, tempShow.CinemaHall.Name);
                listBox3.Items.Remove(listBox3.SelectedItem);
            }
            catch (Exception exp)
            {

            }
        }
    }
}
